const detailMixin = {
	data () {
		return {
			exchangeShow: false,
			catalogs: [],
			characters: [],
			recomes: [],
			loading: false
		}
	},
	methods: {
		async getDetail () {
			return await this.$store.dispatch('network/request', {
				name: 'detail',
				url: this.params.detailUrl,
				source: this.source,
				data: this.params
			})
		},
		async getCatalog () {
			return await this.$store.dispatch('network/request', {
				name: 'catalog',
				url: this.params.catalogUrl,
				source: this.source,
				data: this.params
			})
		},
		async getCharacter () {
			return await this.$store.dispatch('network/request', {
				name: 'character',
				url: this.params.characterUrl,
				source: this.source,
				data: this.params
			})
		},
		async getRecome () {
			return await this.$store.dispatch('network/request', {
				name: 'recome',
				url: this.params.recomeUrl,
				source: this.source,
				data: this.params
			})
		},
		async handleGetDetail () {
			const res = await this.getDetail()
			const data = res.data?.data || {}
			Object.keys(data).forEach(key => {
				this.$set(this.params, key, data[key] || this.params[key])
			})
			if ( this.params.isVip ) {
				this.$refs.dialog.alert({
					title: {
						color: this.skinColor.color_1,
						text: '提示'
					},
					content: {
						color: this.skinColor.color_red,
						text: '付费资源！请支持正版'
					},
					options: {
						bgColor: this.skinColor.color_bg_2,
						type: 2
					}
				})
			}
		},
		async handleGetCatalog () {
			const res = await this.getCatalog()
			let catalogs = res.data?.list || []
			if ( this.params.contextUrl || this.params.src || this.params.content ) {
				catalogs = [Object.assign({}, this.params, {id: this.id + '_1_' + this.source})]
			}
			return catalogs
		},
		async handleGetCharacter () {
			const res = await this.getCharacter()
			return res.data?.list || []
		},
		async handleGetRecome () {
			const res = await this.getRecome()
			return res.data?.list || []
		}
	}
}

export default detailMixin;